<form [formGroup]="form">
  <ix-select
    formControlName="exist_replication"
    [label]="helptext.existReplicationLabel | translate"
    [options]="existReplicationOptions$"
    [tooltip]="helptext.existReplicationTooltip | translate"
  ></ix-select>

  <div class="replication">
    <div class="source">
      <ix-select
        formControlName="source_datasets_from"
        [label]="helptext.sourceDatasetsFromLabel | translate"
        [options]="datasetFromOptions$"
        [tooltip]="helptext.sourceDatasetsFromTooltip | translate"
        [required]="true"
      ></ix-select>
      @if (form.controls.ssh_credentials_source.enabled) {
        <ix-ssh-credentials-select
          formControlName="ssh_credentials_source"
          [label]="helptext.sshCredentialsSourceLabel | translate"
          [tooltip]="helptext.sshCredentialsSourceTooltip | translate"
          [required]="true"
        ></ix-ssh-credentials-select>
      }
      @if (form.controls.source_datasets.enabled) {
        <ix-explorer
          formControlName="source_datasets"
          [label]="helptext.sourceDatasetsLabel | translate"
          [tooltip]="helptext.sourceDatasetsTooltip | translate"
          [multiple]="true"
          [required]="true"
          [rootNodes]="sourceDatasetsRootNodes"
          [nodeProvider]="sourceNodeProvider"
        ></ix-explorer>
      }

      @if (form.controls.recursive.enabled) {
        <ix-checkbox
          formControlName="recursive"
          [label]="helptext.recursiveLabel | translate"
          [tooltip]="helptext.recursiveTooltip | translate"
        ></ix-checkbox>
      }
      @if (snapshotsText) {
        <span class="snapshots-text" [class.warning]="isSnapshotsWarning">{{ snapshotsText }}</span>
      }
      @if (form.controls.custom_snapshots.enabled) {
        <ix-checkbox
          formControlName="custom_snapshots"
          [label]="helptext.customSnapshotsLabel | translate"
          [tooltip]="helptext.customSnapshotsTooltip | translate"
        ></ix-checkbox>
      }
      @if (form.controls.schema_or_regex.enabled) {
        <ix-radio-group
          formControlName="schema_or_regex"
          [label]="schemaOrRegexLabel | translate"
          [required]="true"
          [options]="schemaOrRegexOptions$"
        ></ix-radio-group>
      }
      @if (form.controls.naming_schema.enabled) {
        <ix-input
          formControlName="naming_schema"
          [label]="helptext.namingSchemaLabel | translate"
          [tooltip]="helptext.namingSchemaTooltip | translate"
          [required]="true"
        ></ix-input>
      }
      @if (form.controls.name_regex.enabled) {
        <ix-input
          formControlName="name_regex"
          [label]="helptext.nameRegexLabel  | translate"
          [tooltip]="helptext.nameRegexTooltip | translate"
          [required]="true"
        ></ix-input>
      }
    </div>
    <div class="target">
      <ix-select
        formControlName="target_dataset_from"
        [label]="helptext.targetDatasetFromLabel | translate"
        [tooltip]="helptext.targetDatasetFromTooltip | translate"
        [options]="datasetFromOptions$"
        [required]="true"
      ></ix-select>
      @if (form.controls.ssh_credentials_target.enabled) {
        <ix-ssh-credentials-select
          formControlName="ssh_credentials_target"
          [label]="helptext.sshCredentialsTargetLabel | translate"
          [tooltip]="helptext.sshCredentialsTargetTooltip | translate"
          [required]="true"
        ></ix-ssh-credentials-select>
      }
      @if (form.controls.target_dataset.enabled) {
        <ix-explorer
          formControlName="target_dataset"
          [label]="helptext.targetDatasetLabel | translate"
          [tooltip]="helptext.targetDatasetTooltip | translate"
          [required]="true"
          [rootNodes]="targetDatasetsRootNodes"
          [nodeProvider]="targetNodeProvider"
        ></ix-explorer>
      }
      @if (form.controls.encryption.enabled) {
        <ix-checkbox
          formControlName="encryption"
          [label]="helptext.encryptionLabel | translate"
          [tooltip]="helptext.encryptionTooltip | translate"
        ></ix-checkbox>
      }
      @if (form.controls.encryption.enabled && form.controls.encryption.value) {
        <ix-checkbox
          formControlName="encryption_inherit"
          [label]="helptext.encryptionInheritLabel | translate"
          [tooltip]="helptext.encryptionInheritTooltip | translate"
        ></ix-checkbox>
      }
      @if (form.controls.encryption_key_format.enabled) {
        <ix-select
          formControlName="encryption_key_format"
          [label]="helptext.encryptionKeyFormatLabel | translate"
          [tooltip]="helptext.encryptionKeyFormatTooltip | translate"
          [options]="encryptionKeyFormatOptions$"
          [required]="true"
        ></ix-select>
      }
      @if (form.controls.encryption_key_generate.enabled) {
        <ix-checkbox
          formControlName="encryption_key_generate"
          [label]="helptext.encryptionKeyGenerateLabel | translate"
          [tooltip]="helptext.encryptionKeyGenerateTooltip | translate"
        ></ix-checkbox>
      }
      @if (form.controls.encryption_key_hex.enabled) {
        <ix-input
          formControlName="encryption_key_hex"
          [label]="helptext.encryptionKeyHexLabel  | translate"
          [tooltip]="helptext.encryptionKeyHexTooltip | translate"
          [required]="true"
        ></ix-input>
      }
      @if (form.controls.encryption_key_passphrase.enabled) {
        <ix-input
          formControlName="encryption_key_passphrase"
          type="password"
          [label]="helptext.encryptionKeyPassphraseLabel  | translate"
          [tooltip]="helptext.encryptionKeyPassphraseTooltip | translate"
          [required]="true"
        ></ix-input>
      }
      @if (form.controls.encryption_key_location_truenasdb.enabled) {
        <ix-checkbox
          formControlName="encryption_key_location_truenasdb"
          [label]="helptext.encryptionKeyLocationTruenasdbLabel | translate"
          [tooltip]="helptext.encryptionKeyLocationTruenasdbTooltip | translate"
        ></ix-checkbox>
      }
      @if (form.controls.encryption_key_location.enabled) {
        <ix-input
          formControlName="encryption_key_location"
          [label]="helptext.encryptionKeyLocationLabel  | translate"
          [tooltip]="helptext.encryptionKeyLocationTooltip | translate"
          [required]="true"
        ></ix-input>
      }
    </div>
  </div>

  @if (form.controls.transport.enabled) {
    <ix-radio-group
      formControlName="transport"
      [label]="helptext.transportLabel | translate"
      [tooltip]="helptext.transportTooltip | translate"
      [required]="true"
      [options]="transportOptions$"
    ></ix-radio-group>
  }
  @if (form.controls.sudo.enabled) {
    <ix-checkbox
      formControlName="sudo"
      [label]="'Use Sudo For ZFS Commands' | translate"
      [tooltip]="helptext.sudoTooltip | translate"
    ></ix-checkbox>
  }
  <ix-input
    formControlName="name"
    [label]="helptext.nameLabel | translate"
    [required]="true"
  ></ix-input>
  <ix-form-actions>
    <button
      mat-button
      matStepperNext
      color="primary"
      ixTest="next"
      [disabled]="form.invalid"
    >{{ 'Next' | translate }}</button>
    <button
      mat-button
      type="button"
      color="primary"
      ixTest="advanced"
      (click)="openAdvanced()"
    >{{ 'Advanced Replication Creation' | translate }}</button>
  </ix-form-actions>
</form>
